/*
 * SalaryEmployee.java
 *
 * This class inherited from Employee class, is used to
 * calculate and display the salary details using method overloading.
 *
 * 
 */

package com.javacore.day6.maxsoft2;

/**
 * SalaryEmployee class contains all the details of salaried employees.
 * @author 
 */
public class SalaryEmployee extends Employee{
    
    /** Creates a new instance of SalaryEmployee */
    public SalaryEmployee() {
        
        // Initialize the instance variable with default values
        this("", 0.0, 0, 0);
    }
    
    /**
     * Creates a new instance of SalaryEmployee class and initializes
     * the instance variables.
     * @param name Parameter containing the name of the employee.
     * @param salary Parameter containing salary of the employee.
     * @param grade Parameter containing the grade of the employee.
     * @param deductions Parameter containing the amount to be deducted from
     * employee's salary.
     */
    public SalaryEmployee(String name, double salary, int grade, int deductions) {
        this.name = name;
        this.salary = salary;
        this.grade = grade;
        this.deductions = deductions;
    }
    
    /**
     * Creates a new instance of SalaryEmployee class and initializes
     * the instance variables.
     * @param name Parameter containing the name of the employee.
     * @param salary Parameter containing salary of the employee.
     * @param grade Parameter containing the grade of the employee.
     */
    public SalaryEmployee(String name, double salary, int grade) {
        this(name, salary, grade, 0);
    }
    
    /**
     * Method to calculate the net salary based on perk1 and deductions.
     * @param perk Parameter containing the allowance amount.
     * @return Returns the calculated pay.
     */
    double calculateNetSalary(int perk) {
        return (this.salary + perk) - this.deductions;
    }
    
    /**
     * Method to calculate the net salary based on perk1, perk2 and deductions.
     * @param perk1 Parameter containing the amount of allowance1.
     * @param perk2 Parameter containing the amount of allowance2.
     * @return Returns the calculated salary.
     */
    double calculateNetSalary(int perk1, int perk2) {
        return (this.salary + perk1 + perk2) - this.deductions;
    }
    
    /**
     * Method to display the details of salaried employees.
     */
    void displayDetails() {
        
        // Display employee name
        super.displayDetails();
        
        // Display salary on the basis of grade
        if(grade == 1) {
            System.out.printf("\nNet Salary: %.2f", calculateNetSalary(100));
        } else if(grade == 2) {
            System.out.printf("\nNet Salary: %.2f", calculateNetSalary(100, 200));
        }
    }
    
    /**
     * Instance variable to store salary for salaried employees.
     */
    double salary;
    
    /**
     * Instance variable to store deduction amount.
     */
    double deductions;
    
    /**
     * Instance variable grade to store grade. Employee with grade 1 will get
     * one perk. Employee with grade 2 will get two perks.
     */
    int grade;
}
